<template>
  <div class="container">
    <div class="head-container item">
      <div class="title">治愈管理</div>
      <el-button-group class="checkout-btn-group">
        <el-button class="checkout-btn" @click="queryTableData">
          <i class="el-icon-refresh"></i>
          <span>刷新</span>
        </el-button>
      </el-button-group>
      <div class="search-container">
        <el-input class="query-input"
                  placeholder="请输入姓名"
                  v-model="key"
                  clearable>
        </el-input>
        <el-button class="search-btn" @click="queryTableData">搜索</el-button>
      </div>

    </div>
    <div class="table-container item">
      <el-table
          :header-cell-style="{'text-align':'center'}"
          :cell-style="{'text-align':'center'}"
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column
            prop="base.name"
            label="姓名"
            width="120">
        </el-table-column>
        <el-table-column
            prop="base.age"
            label="年龄"
            width="200">
        </el-table-column>
        <el-table-column
            prop="base.gender"
            label="性别"
            width="80">
        </el-table-column>
        <el-table-column
            :show-overflow-tooltip="true"
            prop="base.address"
            label="住址"
            width="250">
        </el-table-column>
        <el-table-column
            prop="dischargeDate"
            label="出院日期"
            width="150">
        </el-table-column>
        <el-table-column
            prop="current"
            width="180"
            label="感染来源">
        </el-table-column>
        <el-table-column
            label="操作">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click.native.prevent="viewMessage(scope.row)">
              详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          class="pagination"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="total, sizes,prev, pager, next,jumper"
          :page-size="pageSize"
          :page-sizes="[5,10,15]"
          :current-page.sync="pageNum"
          :total="total">
      </el-pagination>
    </div>
    <el-dialog
        title="治愈信息"
        :visible.sync="messageDialogVisible"
        width="53%">
      <div class="dialog-content">
        <div class="base-message content-container">
          <div class="dialog-base-title">基本信息</div>
          <el-table
              class="dialog-base-table"
              :header-cell-style="{'text-align':'center'}"
              :cell-style="{'text-align':'center'}"
              :data="selectRowData"
              border>
            <el-table-column
                prop="base.name"
                label="姓名"
                width="80">
            </el-table-column>
            <el-table-column
                prop="base.gender"
                label="性别"
                width="80">
            </el-table-column>
            <el-table-column
                prop="base.age"
                label="年龄"
                width="80">
            </el-table-column>
            <el-table-column
                prop="base.idCard"
                width="200"
                label="身份证号码">
            </el-table-column>
            <el-table-column
                :show-overflow-tooltip="true"
                prop="base.address"
                label="地址"
                width="160">
            </el-table-column>
            <el-table-column
                prop="base.phone"
                label="电话"
                width="160">
            </el-table-column>
          </el-table>
        </div>
        <div class="treatment-message content-container">
          <div class="dialog-base-title treatment-message-tittle">治疗信息</div>
          <el-descriptions class="margin-top" :column="2" border>
            <el-descriptions-item>
              <template slot="label">
                感染源
              </template>
              {{ patientData ? patientData.infectionSource : "" }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                住院时间
              </template>
              {{ patientData ? patientData.onsetDate : "" }}

            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                是否重症
              </template>
              {{ patientData ? patientData.critical : "" }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                发病症状
              </template>
              {{ patientData ? patientData.symptoms : "" }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                诊治医院
              </template>
              {{ patientData ? patientData.hospital : "" }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                信息备注
              </template>
              {{ patientData ? patientData.note : "" }}
            </el-descriptions-item>
          </el-descriptions>
        </div>
        <div class="inspects-message content-container">
          <div class="dialog-base-title">核酸检测信息</div>
          <el-table class="dialog-base-table"
                    :header-cell-style="{'text-align':'center'}"
                    :cell-style="{'text-align':'center'}"
                    :data="inspects"
                    border>
            <el-table-column
                prop="testDate"
                label="检测时间">
            </el-table-column>
            <el-table-column
                prop="nuTest"
                label="检测结果">
            </el-table-column>
            <el-table-column
                prop="ctTest"
                label="CT结果">
            </el-table-column>
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="messageDialogVisible=false">确 定</el-button>

  </span>
    </el-dialog>
  </div>
</template>

<script>
import {queryCure} from "@/api/cure";
import {formatDate} from "@/utils/date";

export default {
  name: "CureManagementPage",
  data() {
    return {
      tableData: [],
      pageSize: 5,
      pageNum: 1,
      total: 1,
      key: "",
      messageDialogVisible: false,
      selectRowData: [],
      inspects: [],
      patientData: null,
    }
  },
  methods: {
    viewMessage(row) {
      console.log(row)
      this.selectRowData = [];
      this.selectRowData.push(row);

      this.patientData = row.patient;
      this.patientData.onsetDate = formatDate(new Date(this.patientData.onsetDate), "yyyy-MM-dd");

      this.inspects = row.patient.inspects;
      this.inspects.forEach(i => {
        i.testDate = formatDate(new Date(i.testDate), "yyyy-MM-dd");
      })

      this.messageDialogVisible = true;

    },
    handleSizeChange(size) {
      this.pageSize = size;
      this.queryTableData();
    },
    handleCurrentChange(currentPage) {
      this.pageNum = currentPage;
      this.queryTableData();
    },
    queryTableData() {
      queryCure(this.pageNum, this.pageSize,this.key).then(res => {
        res.data.list.forEach(d => {
          d.dischargeDate = formatDate(new Date(d.dischargeDate), "yyyy-MM-dd");
        })
        this.tableData = res.data.list;
        this.pageSize = res.data.pageSize;
        this.total = res.data.total;
        this.pageNum = res.data.pageNum;
      })
    },
  },
  mounted() {
    this.queryTableData();
  }
}
</script>

<style scoped>
.container {
  border-top: 3px solid #3c8dbc;
  border-radius: 3px;
  background-color: white;
  margin-left: 20px;
  margin-right: 20px;
}

.item {
  margin-right: 10px;
  margin-left: 10px;
}

.table-container {
  text-align: center;
}

.checkout-btn {
  margin-top: 10px;
  margin-bottom: 10px;
}

.title {
  font-size: 20px;
  padding-top: 10px;
}

.pagination {
  padding-top: 20px;
  padding-bottom: 20px;
}

.search-container {
  display: inline-block;
  float: right;
}

.query-input {
  display: inline-block;
  margin-right: 10px;
  width: 180px;
}

.dialog-base-title {
  font-size: 15px;
  padding: 5px;
  display: inline-block;
}

.dialog-base-table {
  width: 100%;
}

.content-container {
  margin-top: 20px;
  background-color: #E9EEF3;
}
</style>
